# coding:utf-8
# writingtime: 2022-6-29
# author: wanjun

'''

FS :     0.80       -> ([0.80,0.80],[0.80,0.80])
IFS:    (0.20,0.80) -> ([0.20,0.20],[0.80,0.80])
PFS:    (0.10,0.93) -> ([0.10,0.10],[0.93,0.93])
q-ROFS: (0.50,0.90) -> ([0.50,0.50],[0.90,0.90])

IVFS:     (0.60,0.80)               -> ([0.60,0.80],[0.20,0.40])
IVIFS:    ([0.20,0.50],[0.30,0.50]) -> ([0.20,0.50],[0.30,0.50])
IVPFS:    ([0.20,0.50],[0.20,0.70]) -> ([0.20,0.50],[0.20,0.70])
IVq-ROFS: ([0.20,0.50],[0.60,0.80]) -> ([0.20,0.50],[0.60,0.80])

'''

'''FS、IFS、PFS、q-ROFS转化为IVq-ROFS'''
class DataConversionFS:

    def transA(self, data):
        '''
        function: 将单个的FS、IFS、PFS、q-ROFS的转化为IVq-ROFS
        :param data: 模糊数
        :return: 区间值广义证正交模糊数以及最小的q值
        '''
        q = 1
        if type(data) == int or type(data) == float:
            IVq_ROF = ([data, data], [data, data])
        else:
            IVq_ROF = ([data[0], data[0]], [data[1], data[1]])

        while IVq_ROF[0][1] ** q + IVq_ROF[1][1] ** q >= 1:
            q += 1

        return [IVq_ROF, q]

    def transVector(self, data_vector):
        '''
        function: 将一个向量的FS、IFS、PFS、q-ROFS的转化为IVq-ROFS
        :param data: 模糊向量
        :return: 向量与最小的q值
        '''
        temp = [self.transA(i) for i in data_vector]
        max_q = max([i[1] for i in temp])
        data_list = [i[0] for i in temp]

        return [data_list, max_q]

    def transMatrix(self, data_matrix):
        '''
        function: 将一个矩阵的FS、IFS、PFS、q-ROFS的转化为IVq-ROFS
        :param data_matrix: 模糊矩阵
        :return: 矩阵与最小的q的值
        '''
        temp = [self.transVector(i) for i in data_matrix]
        max_q = max([i[1] for i in temp])
        data_matrix = [i[0] for i in temp]

        return [data_matrix, max_q]

'''IVFS,IVIFS,IVPFS转化为IVq-ROFS'''
class DataConversionIFS:

    def transA(self,data):
        '''
        function: IVFS,IVIFS,IVPFS转化为IVq-ROFS
        :param data: IVFS,IVIFS,IVPFS
        :return: IVq-ROFS和最小的q的值
        '''
        q=1
        if type(data[0])==int or type(data[0])==float:
            IVq_ROF=([data[0],data[1]],[1-data[1],1-data[0]])
        else:
            IVq_ROF=data

        while IVq_ROF[0][1] ** q + IVq_ROF[1][1] ** q >= 1:
            q += 1

        return [IVq_ROF,q]

    def transVector(self, data_vector):
        '''
        function: IVFS,IVIFS,IVPFS转化为IVq-ROFS
        :param data: 模糊向量
        :return: 向量与最小的q值
        '''
        temp = [self.transA(i) for i in data_vector]
        max_q = max([i[1] for i in temp])
        data_list = [i[0] for i in temp]

        return [data_list, max_q]

    def tranMatrix(self, data_matrix):
        '''
        function: IVFS,IVIFS,IVPFS转化为IVq-ROFS
        :param data_matrix: 模糊矩阵
        :return: 矩阵与最小的q的值
        '''
        temp = [self.transVector(i) for i in data_matrix]
        max_q = max([i[1] for i in temp])
        data_matrix = [i[0] for i in temp]

        return [data_matrix, max_q]



if __name__ == '__main__':
    aFS = 0.8
    FS_list = [0.2, 0.4, 0.6, 0.8]
    IFS_list = [(.2, .4), (.3, .8), (.2, .3)]
    IFS_matrix = [[(.2, .4), (.3, .8), (.2, .3)],
                  [(.2, .4), (.3, .8), (.2, .3)]]
    example = DataConversionFS()
    # print(example.transA(aFS))
    # print(example.transVector(IFS_list))
    print(example.transMatrix(IFS_list))
